<!--
 * @Author: 1243sd 782012816@qq.com
 * @Date: 2024-03-18 22:47:51
 * @LastEditors: 1243sd 782012816@qq.com
 * @LastEditTime: 2024-04-05 18:31:47
 * @FilePath: \frontend-ykt-admin\src\views\withdraw\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-------- 提现申请 --------->
<template>
    <div class="container">
        <b-card-new>
            <b-query-form-new ref="bForm" :data="formData" :form="dataForm.query" @search="handleSearch"></b-query-form-new>
            <b-query-table ref="bTable" :init-columns="initColumns()" :data-form="dataForm" :handleList="handleList"></b-query-table>
        </b-card-new>
        <!-- 操作弹窗 -->
        <el-dialog :title="['通过', '拒绝', '确认已打款'][operationPopup.type - 1]" lock-scroll width="430px" :visible.sync="operationPopup.isShow">
            <el-form label-width="70px">
                <div v-if="operationPopup.type == 1">已核实信息，确认通过！</div>
                <el-input type="textarea" maxlength="300" placeholder="请输入拒绝原因" rows="5" v-model="operationPopup.data.refuse_reason" v-else-if="operationPopup.type == 2"></el-input>
                <el-form-item label="打款时间" v-else class="mb0" required>
                    <el-date-picker
                        style="width: 100%;"
                        v-model="operationPopup.data.wd_time"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <b-button-new text="取消" @click="operationPopup.isShow = false"></b-button-new>
                <b-button-new text="确定" @click="handleConfirm"></b-button-new>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import mixinPageHeight from "@/mixinPageHeight"
export default {
    mixins:[mixinPageHeight],
    data() {
        return {
            formData:[
                
                { typeCode: "selectFilter", title: "会员名称", name: "ofa_user_id", jsName: "member", fnName: "member_list", vname: "nickname" },
                { typeCode: "selectFilter", title: "邀请人", name: "inviter_id", jsName: "member", fnName: "member_list", vname: "nickname", sname: 'keywords' },
                { typeCode: "selectFilter", title: "代理人", name: "proxy_id", jsName: "member", fnName: "member_list", vname: "nickname", sname: 'keywords' },
                { typeCode: "select", title: "提现状态", name: "wd_status", kname: 'code', vname: 'name', optionData: [] },
                { typeCode: "datePickerRangeI", title: "支付时间", name: "wd_time", start: "wd_time_start", end: "wd_time_end" },
                { typeCode: "datePickerRangeI", title: "创建时间", name: "created_time", start: "created_at_start", end: "created_at_end" },
            ],
            dataForm:{
                url:"api/withdraw/page_list",
                query:{
                    ofa_user_id: "", // 公众号会员ID
                    wd_status: "", // 状态   
                    inviter_id: "", // 邀请人
                    proxy_id: "", // 代理人
                    wd_time_start: "", // 支付开始时间
                    wd_time_end: "", // 支付结束时间
                    created_at_start: "", // 创建开始时间
                    created_at_end: "", // 创建结束时间
                }
            },
            // 操作弹窗
            operationPopup: {
                isShow: false,
                type: '', // 1通过 2拒绝 3确认已打款
                data: {}
            },
            // 按钮
            handleList: [
                {
                    name: '导出',
                    isHollow: true,
                    btnCode: '',
                    btnClick: () => this.$api.withdraw.withdraw_export({...this.dataForm.query, page: 1, page_size: 1})
                }
            ]
        }
    },
    created() {
        
        // 提现状态枚举
        this.$api.setting.get_options('ofa_user.withdraw_status').then(res => {
            this.formData[1].optionData = res || []
        })
    },
    methods:{
        initColumns() {
            return [
                { title:"会员id", valueName:"ofa_user_id" },
                { title:"会员昵称", valueName:"ofa_user_nickname", isShowTip: true, width: 150 },
                { title:"会员类型", valueName:"ofa_user_type_name" },
                { title:"会员联系电话", valueName:"ofa_user_mobile", width: 150 },
                { title:"当前积分", valueName:"ofa_points" },
                // { title:"是否签约", valueName:"ofa_is_signed", customRander: row => ['未签约', '已签约'][row.ofa_is_signed] },
                { title:"提现积分", valueName:"points" },
                { title:"提现状态", valueName:"wd_status_name" },
                { title:"拒绝原因", valueName:"refuse_reason" },
                { title:"打款时间", valueName:"wd_time" },
                { title:"申请时间", valueName:"created_at", width: 170 },
                { title:"操作", fixed: 'right', width: 220, customRander: (row) => <div>
                    { row.wd_status == 'PENDING_REVIEW' && <BTableOperation list={
                        [
                            { name: '通过', btnCode: '16', btnClick: () => this.handleOperation(row.id, 1, true)},
                            { name: '拒绝', btnCode: '16', btnClick: () => this.handleOperation(row.id, 2, false)},
                        ]
                        }></BTableOperation> 
                    }
                    { row.wd_status == 'PENDING_PAY' && <BTableOperation list={
                        [
                            { name: '确认已打款', btnCode: '17', btnClick: () => this.handleOperation(row.id, 3)}
                        ]
                        }></BTableOperation> 
                    }
                </div>
                }
            ]
        },
        // 操作 type = 1通过 2拒绝 3确认已打款
        handleOperation(id, type, is_pass) {
            this.operationPopup.type = type
            if (type == 3) {
                this.operationPopup.data =  { id, wd_time: '' }
            } else {
                this.operationPopup.data = { id, is_pass, refuse_reason: '' }
            }
            this.operationPopup.isShow = true
        },
        // 点击保存
        handleConfirm() {
            // 确认已打款
            if (this.operationPopup.type == 3) {
                if (!this.operationPopup.data.wd_time) {
                    this.$message.error('请先选择打款时间')
                    return
                }
                this.$api.withdraw.withdraw_confirm_send_money(this.operationPopup.data.id, this.operationPopup.data).then(res => {
                    this.$message.success('确认已打款')
                    this.handleRefresh()
                })
            } else {
                this.$api.withdraw.withdraw_apply(this.operationPopup.data.id, this.operationPopup.data).then(res => {
                    this.$message.success('操作成功')
                    this.handleRefresh()
                })
            }
        }
    }
}
</script>